#include "image.h"

Image::Image(int w,int h):
	_w(w),
	_h(h)
{
	if(w && h){
		this->img = new int[w*h];
		for(register int y = 0; y<_h;++y){
			for(register int x = 0; x<_w;++x){
				if(x != y)this->getPixel(x,y) = 0;
				else this->getPixel(x,y) = 1;
			}
		}
	}
}

Image::~Image(void)
{
	if(this->img != NULL)delete[] this->img;
}


void Image::print(void)
{
	//for(register int y = 0; y<_h;++y){
	for(register int y = _h-1; y >= 0;--y){
		for(register int x = 0; x<_w;++x){
			cout<<this->getPixel(x,y)<<" ";
			
		}
		cout<<endl;
	}
}

void Image::create(int w,int h)
{
	if(this->img != NULL)delete[] this->img;
	this->img = new int[w*h];
	this->_h = h;
	this->_w = w;
	for(register int y = 0; y<_h;++y){
		for(register int x = 0; x<_w;++x){
			if(x != y)this->getPixel(x,y) = 0;
			else this->getPixel(x,y) = 1;
		}
	}
	
}

bool Image::existPixel(int x, int y)
{
	if(x < 0)return false;
	if(x >= _w)return false;
	if(y < 0)return false;
	if(y >= _h)return false;
	return true;
}
